<template>
  <div class="noshadow">
    <searchData :showTitleName="false" :searchData="searchArr" @search="search"></searchData>
    <a-row :gutter="10">
      <a-col :span="24">
        <list-table
          ref="table"
          :columns="columns"
          :request="loadData"
          :isScrollX="false" 
          :select-config="{use: true, type: 'checkbox', rowKey: 'id'}"
        >
          <template
            slot="prefix"
          >
            <a-button
              v-btnPermission="isCom ? 'stm_010_bcadd_03' : 'stm_010_pdadd_04'"
              :loading="addLoading"
              type="primary"
              @click="handleManage('add')"
            >
              新增责任书
            </a-button>
          </template>
          
          <template
            slot="statusSer"
            slot-scope="text, record"
          >
            <list-status2
              :status="record.status"
              :text="text"
            />
          </template>
          
          <span slot="action" slot-scope="text, record">
            <MoreButton>
              <a v-btnPermission="isCom ? 'stm_010_bcloo_06' : 'stm_010_pdloo_09'" @click="handleManage('look', record.id)">查看</a>
              <span v-btnPermission="isCom ? 'stm_010_bcedi_05' : 'stm_010_pdedi_08'" v-if="record.status == 'DRAFT' || record.status == 'REJECTED'">
                <a-divider type="vertical" />
                <a @click="handleManage('edit', record.id)">编辑</a>
              </span>
              <!-- <span v-btnPermission="isCom ? 'stm_010_bcdel_07' : 'stm_010_pddel_10'" v-if="record.status == 'DRAFT'">
                <a-divider type="vertical" />
                <a @click="remove(record.id)">删除</a>
              </span> -->
              <!-- <span v-if="record.status == 'SUBMITTED' || record.status == 'PAST' || record.status == 'REJECTED'">
                <a-divider type="vertical" />
                <approval-button :id="record.id" text="审批详情" />
              </span> -->
            </MoreButton>
          </span>
        </list-table>
      </a-col>
    </a-row>
  </div>
  
</template>

<script>
import { STable } from '@/components' // 表格
import SelectYear from '../components/SelectYear.vue'
import list_status2 from '@/components/list_status2/list_status2'
import SelectSubCompany from '@/components/Select/SelectSubCompany.vue'
import { getResponseList, delResponse } from '@/api/science/quantufiyResponse'
import OrgTreeSelect from '@/components/OrgTreeSelect'
const searchArr = [
  // 搜索框
  // {
  //   name: '项目名称',
  //   value: 'projectName',
  //   type: 'input',
  // },
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属单位',
  //   valueKey: 'searchQuery',
  //   type: OrgTreeSelect,
  // },
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'orgId',
  //   type: SelectSubCompany,
  // },
  // {
  //   name: '状态',
  //   value: 'status',
  //   type: 'select',
  //   data: [
  //     // DRAFT, SUBMITTED, PAST, REJECTED 
  //     { label: '待提交审批', value: 'DRAFT'},
  //     { label: '审批中', value: 'SUBMITTED'},
  //     { label: '审批通过', value: 'PAST'},
  //     { label: '审批不通过', value: 'REJECTED'},
  //   ]
  // },
  {
    name: '年度',
    valueKey: 'year',
    type: SelectYear,
  },
  {
    name: '创建时间',
    value: 'createTime',
    type: 'dateRange',
  }
]
const columns = [
  {
    title: '项目名称',
    ellipsis: true,
    dataIndex: 'projectName',
  },
  {
    title: '单位名称',
    ellipsis: true,
    // width: '200px',
    dataIndex: 'orgName',
  },
  {
    title: '年度',
    ellipsis: true,
    dataIndex: 'year',
    // width: '120px',
  },
  {
    title: '创建人',
    ellipsis: true,
    // width: '150px',
    dataIndex: 'creatorName',
  },
  {
    title: '创建时间',
    ellipsis: true,
    // width: '150px',
    dataIndex: 'createTime',
  },
  // {
  //   title: '状态',
  //   ellipsis: true,
  //   // width: '150px',
  //   dataIndex: 'statusSer',
  //   scopedSlots: { customRender: 'statusSer' }
  // },
  {
    title: '操作',
    dataIndex: 'actions',
    width: '180px',
    fixed: 'right',
    scopedSlots: { customRender: 'action' },
  },
]
export default {
  name:'a'+ Date.now(),
  components: {
    'list-status2': list_status2,
    SelectSubCompany,
    SelectYear
  },
  props: {
    tab: {
      type: Object,
      default() {
          return {
            name: '分公司'
          }
      }
    }
  },
  computed: {
    isCom() {
      return this.tab.name.includes('分公司')
    },
    columns() {
      return (!this.isCom) ? columns : [...columns].slice(1)
    },
    searchArr() {
      return (!this.isCom) ? searchArr : [...searchArr].slice(1)
    }
  },
  data() {
    // this.columns = columns
    // this.searchArr = searchArr
    return {
      addLoading: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        let that = this
        const obj = (!this.isCom) ? { projectLive: true } : {};
        const requestParameters = Object.assign(obj, parameter, that.queryParam)
        return getResponseList(requestParameters).then((res) => {
          return res
        })
      },
    }
  },
  mounted() {
    let that = this
  },
  methods: {
    remove(id) {
      let that = this
      that.$confirm({
        title: '提示',
        content: '确定是否删除？',
        okText: '确定',
        cancelText: '取消',
        onOk() {
          return delResponse(id).then((res) => {
            if (res.code == 200 || res.data.code == 200) {
              that.$message.success('删除成功！')
              that.$refs.table.getData(null, true)
            }
          })
        },
      })
    },
    search(value) {
      // 赋值表单
      if (value) {
        this.queryParam = value
        if (this.queryParam.createTime?.length > 0) {
          this.queryParam.beginTime = this.$dateFormat(this.queryParam.createTime[0], 'D')
          this.queryParam.endTime = this.$dateFormat(this.queryParam.createTime[1], 'D')
          delete this.queryParam.createTime
        }
      }
      this.$refs.table.getData(null, true)
    },
    // 新增、编辑、查看
    handleManage(type, id) {
      this.$router.push({
        path: '/science/quantitative/edit',
        query: {
          levelTypeId: this.tab.id,
          isCom: this.isCom,
          type,
          id
        },
      })
    },
  },
}
</script>
<style>
  .noshadow .ant-card {
    box-shadow: 0 0;
  }
</style>

